#include<iocc2530.h>
#include"led.h"

void clock_init(void){
  CLKCONCMD &= ~0x40;
  while(CLKCONSTA & 0x40);
  CLKCONCMD &= ~0x07;
  CLKCONCMD &= ~0x38;
}

void timer1_init(void){
  T1CTL |=0x0F;
  T1CC0L = 0x24;
  T1CC0H = 0xF4;
  T1CCTL0 |= 0x44;
  T1IE = 1;
  EA = 1;
}

void main(void){
  clock_init();
  led_init();
  timer1_init();
  
  while(1);
}

int i = 1;
#pragma vector = T1_VECTOR
__interrupt void T1_ISR(void){
  EA = 0;
  i=i%8;
  if(T1STAT & 0x20){
   if(i=1 || i==2)
   {
     LED1 = !LED1;
   }
   else if(i=3 || i==4)
   {
     LED2 = !LED2;
   }
   else if(i=5 || i==6)
   {
     LED3 = !LED3;
   }
   else
   {
     LED4 = !LED4;
   }
   i++;
    T1STAT = 0; 
  }
  EA = 1;
}